﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.SheepMomWeaningCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Dto.InputDto;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepMomWeaningHandler
{
    public class SheepWeaningSelectHandler:IRequestHandler<SheepWeaningSelectCommand,Results<List<SheepMomWeaning>>>
    {
        private readonly ISheepWeaningService _sheepWeanService;
        private readonly IMapper _mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sheepWeanService"></param>
        /// <param name="mapper"></param>
        public SheepWeaningSelectHandler(ISheepWeaningService sheepWeanService, IMapper mapper)
        {
            _sheepWeanService = sheepWeanService;
            _mapper = mapper;
        }
        /// <summary>
        /// 种母断奶列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<List<SheepMomWeaning>>> Handle(SheepWeaningSelectCommand request, CancellationToken cancellationToken)
        {
            var weanList = _mapper.Map<SheepWeaningInput>(request);

            var list = _mapper.Map<List<SheepMomWeaning>>(await _sheepWeanService.GetSheepWeaning(weanList));

            return Results<List<SheepMomWeaning>>.DataResult(list);
        }




    }
}
